package hello1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class HelloWorldServlet extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setContentType("text/html; charset=euc-kr");
        req.setCharacterEncoding("KSC5601");
        PrintWriter out = res.getWriter();
        String text = req.getParameter("message");
        
        try {                        
                Resource resource = new ClassPathResource("hello1.xml");
                BeanFactory factory = new XmlBeanFactory(resource);
                HelloWorld bean1 = (HelloWorld)factory.getBean("hello");
                String s = bean1.sayHello(text);
                out.println(s);                        
        }
        catch(Exception e) {
                
        }
}

public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
 {
  doGet(req, resp);
 }
}
